From 21da19f8a40416c07f49c25d5d25b00d771304cb Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 25 Jan 2003 18:55:28 +0000 Subject: [PATCH] From Rick Richardson: This patch adds a proper usage message (although the wording may need to be fixed), more standards-like option parsing, and the ability to specify the input and output files as positional parameters rather than options. --- main.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++--------- vecs.c | 2 +- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index 6e5cda912..d44b09dd4 100644 --- a/main.c +++ b/main.c @@ -26,9 +26,33 @@ global_options global_opts; void usage(const char *pname) { - printf("GPSBabel Version %s. http://gpsbabel.sourceforge.net\n",VERSION ); - printf("Usage: %s [-s] [-t|-w|-r] -i -f -o -F \n", pname); - printf("Supported file types:\n"); + printf("GPSBabel Version %s. http://gpsbabel.sourceforge.net\n\n", + VERSION ); + printf( +"Usage:\n" +" %s [options] -i INTYPE -f INFILE -o OUTTYPE -F OUTFILE\n" +" %s [options] -i INTYPE -o OUTTYPE INFILE [OUTFILE]\n" +"\n" +" Converts GPS route and waypoint data from one format type to another.\n" +" The input type and filename are specified with the -i INTYPE\n" +" and -f INFILE options. The output type and filename are specified\n" +" with the -o OUTTYPE and -F OUTFILE options.\n" +"\n" +" In the second form of the command, INFILE and OUTFILE are the\n" +" first and second positional (non-option) arguments.\n" +"\n" +"Options:\n" +" -s Synthesize shortnames\n" +" -r Process route information\n" +" -t Process track information\n" +" -w Process waypoint information [default]\n" +" -D level Set debug level [%d]\n" +"\n" +"File Types (-i and -o options):\n" + , pname + , global_opts.debug_level + ); + disp_vecs(); } @@ -58,7 +82,10 @@ main(int argc, char *argv[]) char *optarg; if (argv[argn][0] != '-') { - fatal ("argument '%s' not understood\n",argv[argn]); + break; + } + if (argv[argn][1] == '-') { + break; } if (argv[argn][1] == '?' || argv[argn][1] == 'h') { @@ -67,20 +94,22 @@ main(int argc, char *argv[]) } c = argv[argn][1]; - optarg = argv[argn+1]; switch (c) { case 'i': + optarg = argv[argn][2] + ? argv[argn]+2 : argv[++argn]; ivecs = find_vec(optarg, &ivec_opts); - argn++; break; case 'o': + optarg = argv[argn][2] + ? argv[argn]+2 : argv[++argn]; ovecs = find_vec(optarg, &ovec_opts); - argn++; break; case 'f': + optarg = argv[argn][2] + ? argv[argn]+2 : argv[++argn]; fname = optarg; - argn++; if (ivecs == NULL) { fatal ("No valid input type specified\n"); } @@ -89,8 +118,9 @@ main(int argc, char *argv[]) ivecs->rd_deinit(); break; case 'F': + optarg = argv[argn][2] + ? argv[argn]+2 : argv[++argn]; ofname = optarg; - argn++; if (ovecs) { ovecs->wr_init(ofname, ovec_opts); ovecs->write(); @@ -110,8 +140,9 @@ main(int argc, char *argv[]) global_opts.objective = rtedata; break; case 'D': + optarg = argv[argn][2] + ? argv[argn]+2 : argv[++argn]; global_opts.debug_level = atoi(optarg); - argn++; break; case '^': disp_formats(); @@ -123,6 +154,26 @@ main(int argc, char *argv[]) } } + /* + * Allow input and output files to be specified positionally + * as well. This is the typical command line format. + */ + argc -= argn; + argv += argn; + if (argc > 2) { + fatal ("Extra arguments on command line\n"); + } + else if (argc) { + ivecs->rd_init(argv[0], ivec_opts); + ivecs->read(); + ivecs->rd_deinit(); + if (argc == 2 && ovecs) { + ovecs->wr_init(argv[1], ovec_opts); + ovecs->write(); + ovecs->wr_deinit(); + } + } + if (ovecs == NULL) waypt_disp_all(waypt_disp); diff --git a/vecs.c b/vecs.c index f273878f5..f7dfb6bd6 100644 --- a/vecs.c +++ b/vecs.c @@ -296,7 +296,7 @@ disp_vecs(void) { vecs_t *vec; for (vec = vec_list; vec->vec; vec++) { - printf("%-20.20s %-50.50s\n", + printf(" %-20.20s %-50.50s\n", vec->name, vec->desc); } } -- 2.30.2